<template>
  <div class="add_body">
    <Header>
      <van-icon name="arrow-left" size="22" slot="left" />
      <span slot="center">新增地址</span>
    </Header>
    <van-address-edit :area-list="areaList" show-postal show-set-default show-search-result
      :search-result="searchResult" :area-columns-placeholder="['请选择', '请选择', '请选择']" @save="onSave" />
  </div>
</template>

<script>
import { areaList } from '@vant/area-data'
import Header from '@/components/common/Header.vue'
import { incrementAddressRequest } from '@/network/api/address'
export default {
  name: 'add',
  components: {
    Header
  },
  data() {
    return {
      userId: 0,
      searchResult: [],
      areaList,
    }
  },
  methods: {
    async onSave(content) {
      content.isDefault_int = content.isDefault ? 1 : 0
      content.userId = this.$store.state.user.userId
      await incrementAddressRequest(content)
      this.$router.back()
    }
  },
  created() {
    this.userId = this.$route.query.userId
  },
}
</script>

<style scoped lang="less">
.add_body /deep/ .van-button {
  background-color: #b0352f;
}
</style>

